In [1]:
%load_ext autoreload
%autoreload 2
In [2]:
import matplotlib
matplotlib.use('nbagg')
%matplotlib inline
import matplotlib.pyplot as plt
In [3]:
!ls -ltrh ../mat/*
In [4]:
%%writefile ../scenario_line_master.py
#!/usr/bin/env python
# -*- coding: utf8 -*-
import elasticite as el
import numpy as np
import os
def master(e, filename):
if e.structure: N_lame = e.N_lame-e.struct_N
else: N_lame = e.N_lame
def montage(z, z_in, damp_tau=0.):
z_out = z.copy()
z_s = z_in.copy()
#if damp_tau>0:
# max_time = z_in.shape[0]/e.desired_fps
# time = np.linspace(0., max_time, z_in.shape[0])
# smooth = 1.-np.exp((np.cos(2*np.pi* time / max_time)-1)/(damp_tau / max_time)**2)
# z_s[:, 1:] *= smooth[:, np.newaxis]
#print (z_out[0, 0], z_out[-1, 0], z_s[0, 0], z_s[-1, 0])
z_s[:, 0] += z_out[-1, 0] + 1./e.desired_fps # increment the time on the new array
#print (z_out.shape, z_s.shape, z_s[0, 0], z_s[-1, 0])
return np.vstack((z_out, z_s))
def revert(z_in):
z_s = z_in.copy()
z_s[:, 1:] = z_s[:, 1:][:, ::-1]
return z_s
def mirror(z_in):
z_s = z_in.copy()
z_s[:, 1:] = -z_s[:, 1:]
return z_s
def interleave(z_1, z_2):
z_s_1 = z_1.copy()
z_s_2 = z_2.copy()
z_s_1[:, 1::2] = z_s_2[:, 1::2]
return z_s_1
matpath = 'mat/'
z_s = {}
print('importing scenarii')
for scenario in [#'line_vague_dense', 'line_vague_solo',
'line_onde_dense', 'line_onde_solo', 'line_fresnelastique',
'line_fresnelastique_choc', 'line_fresnelastique_chirp',
'line_geometry', 'line_geometry_45deg', 'line_geometry_90deg', 'line_geometry_structure']:
z_s[scenario] = np.load(os.path.join(matpath, scenario + '.npy'))
print(scenario)
el.check(e, z_s[scenario])
print('finished importing scenarii')
###########################################################################
burnout_time = 0.1
z = np.zeros((1, N_lame+1)) # zero at zero
z = np.vstack((z, np.hstack((np.array(burnout_time), np.zeros(N_lame) ))))
###########################################################################
# z = montage(z, z_s['line_onde_solo'])
z = montage(z, z_s['line_onde_dense'])
###########################################################################
z = montage(z, z_s['line_geometry_90deg'])
z = montage(z, z_s['line_geometry_45deg'])
z = montage(z, z_s['line_geometry_structure'])
z = montage(z, z_s['line_geometry'])
z = montage(z, mirror(z_s['line_geometry_structure']))
z = montage(z, mirror(z_s['line_geometry_45deg']))
z = montage(z, mirror(z_s['line_geometry_90deg']))
###########################################################################
# z = montage(z, z_s['line_onde_solo'])
z = montage(z, revert(z_s['line_onde_dense']))
# z = montage(z, revert(z_s['line_onde_solo']))
###########################################################################
z = montage(z, z_s['line_geometry_structure'])
z = montage(z, z_s['line_geometry'])
z = montage(z, z_s['line_fresnelastique'])
z = montage(z, mirror(z_s['line_fresnelastique']))
z = montage(z, z_s['line_fresnelastique_chirp'])
z = montage(z, z_s['line_fresnelastique_choc'])
z = montage(z, z_s['line_geometry'])
z = montage(z, z_s['line_geometry_structure'])
###########################################################################
z = montage(z, z_s['line_fresnelastique'])
z = montage(z, interleave(z_s['line_fresnelastique'], mirror(z_s['line_fresnelastique'])))
z = montage(z, interleave(z_s['line_fresnelastique_chirp'], mirror(z_s['line_fresnelastique_choc'])))
z = montage(z, interleave(z_s['line_fresnelastique_choc'], mirror(z_s['line_fresnelastique_chirp'])))
z = montage(z, z_s['line_fresnelastique'])
###########################################################################
z = montage(z, revert(z_s['line_onde_dense']))
# z = montage(z, revert(z_s['line_onde_solo']))
###########################################################################
# check that there is not overflow @ 30 fps
el.check(e, z)
###########################################################################
# save the file
np.save(filename, z)
return z_s
if __name__ == "__main__":
import sys
if len(sys.argv)>1: mode = sys.argv[1]
else: mode = 'both'
filename = 'mat/master.npy'
e = el.EdgeGrid(N_lame=25, grid_type='line', mode=mode,
verb=False, filename=filename)
if mode == 'writer':
z_s = master(e, filename)
else:
# running the code
el.main(e)
In [5]:
%cd ..
!rm mat/master.npy
%run scenario_line_master.py writer
%cd posts
In [6]:
z = np.load('../mat/master.npy')
fig, ax = plt.subplots(figsize=(15, 3))
_ = ax.plot(z[:, 0])
ax.axis('tight')
Out[6]:
In [7]:
fig, ax = plt.subplots(figsize=(15, 3))
_ = ax.plot(z[:, 0], z[:, 1:])
ax.axis('tight')
Out[7]:
In [8]:
%%writefile ../scenario_line_master_dimanche.py
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys
sys.path.append('/home/pi/elasticte/')
import elasticite as el
import numpy as np
import os
def master(e, filename):
if e.structure: N_lame = e.N_lame-e.struct_N
else: N_lame = e.N_lame
def montage(z, z_in, damp_tau=0.):
z_out = z.copy()
z_s = z_in.copy()
#if damp_tau>0:
# max_time = z_in.shape[0]/e.desired_fps
# time = np.linspace(0., max_time, z_in.shape[0])
# smooth = 1.-np.exp((np.cos(2*np.pi* time / max_time)-1)/(damp_tau / max_time)**2)
# z_s[:, 1:] *= smooth[:, np.newaxis]
#print (z_out[0, 0], z_out[-1, 0], z_s[0, 0], z_s[-1, 0])
z_s[:, 0] += z_out[-1, 0] + 1./e.desired_fps # increment the time on the new array
#print (z_out.shape, z_s.shape, z_s[0, 0], z_s[-1, 0])
return np.vstack((z_out, z_s))
def revert(z_in):
z_s = z_in.copy()
z_s[:, 1:] = z_s[:, 1:][:, ::-1]
return z_s
def mirror(z_in):
z_s = z_in.copy()
z_s[:, 1:] = -z_s[:, 1:]
return z_s
def interleave(z_1, z_2):
z_s_1 = z_1.copy()
z_s_2 = z_2.copy()
z_s_1[:, 1::2] = z_s_2[:, 1::2]
return z_s_1
matpath = 'mat/'
z_s = {}
print('importing scenarii')
for scenario in [#'line_vague_dense', 'line_vague_solo',
'line_onde_dense', 'line_onde_solo', 'line_fresnelastique',
'line_fresnelastique_choc', 'line_fresnelastique_chirp',
'line_geometry', 'line_geometry_45deg', 'line_geometry_90deg', 'line_geometry_structure']:
z_s[scenario] = np.load(os.path.join(matpath, scenario + '.npy'))
print(scenario)
el.check(e, z_s[scenario])
print('finished importing scenarii')
###########################################################################
burnout_time = 0.1
z = np.zeros((1, N_lame+1)) # zero at zero
z = np.vstack((z, np.hstack((np.array(burnout_time), np.zeros(N_lame) ))))
###########################################################################
# z = montage(z, z_s['line_onde_solo'])
z = montage(z, z_s['line_onde_dense'])
###########################################################################
# z = montage(z, z_s['line_geometry_90deg'])
z = montage(z, z_s['line_geometry_45deg'])
z = montage(z, z_s['line_geometry_structure'])
z = montage(z, z_s['line_geometry'])
z = montage(z, mirror(z_s['line_geometry_structure']))
z = montage(z, mirror(z_s['line_geometry_45deg']))
# z = montage(z, mirror(z_s['line_geometry_90deg']))
###########################################################################
# z = montage(z, z_s['line_onde_solo'])
z = montage(z, revert(z_s['line_onde_dense']))
# z = montage(z, revert(z_s['line_onde_solo']))
###########################################################################
z = montage(z, z_s['line_geometry_structure'])
z = montage(z, z_s['line_geometry'])
z = montage(z, z_s['line_fresnelastique'])
z = montage(z, mirror(z_s['line_fresnelastique']))
z = montage(z, z_s['line_fresnelastique_chirp'])
z = montage(z, z_s['line_fresnelastique_choc'])
z = montage(z, z_s['line_geometry'])
z = montage(z, z_s['line_geometry_structure'])
###########################################################################
z = montage(z, z_s['line_fresnelastique'])
z = montage(z, interleave(z_s['line_fresnelastique'], mirror(z_s['line_fresnelastique'])))
z = montage(z, interleave(z_s['line_fresnelastique_chirp'], mirror(z_s['line_fresnelastique_choc'])))
z = montage(z, interleave(z_s['line_fresnelastique_choc'], mirror(z_s['line_fresnelastique_chirp'])))
z = montage(z, z_s['line_fresnelastique'])
###########################################################################
z = montage(z, revert(z_s['line_onde_dense']))
# z = montage(z, revert(z_s['line_onde_solo']))
###########################################################################
# check that there is not overflow @ 30 fps
el.check(e, z)
###########################################################################
# save the file
np.save(filename, z)
return z_s
if __name__ == "__main__":
import sys
if len(sys.argv)>1: mode = sys.argv[1]
else: mode = 'both'
#filename = '/home/pi/elasticte/mat/master_dimanche.npy'
filename = 'mat/master_dimanche.npy'
e = el.EdgeGrid(N_lame=25, grid_type='line', mode=mode,
verb=False, filename=filename)
if mode == 'writer':
z_s = master(e, filename)
else:
# running the code
el.main(e)
In [9]:
%cd ..
#!rm mat/master_dimanche.npy
%run scenario_line_master_dimanche.py writer
%cd posts
In [10]:
fig, ax = plt.subplots(figsize=(15, 3))
_ = ax.plot(z[:, 0], z[:, 1:])
ax.axis('tight')
Out[10]:
In [11]:
import matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
damp_tau = 60.
max_time = z_s['line_geometry'].shape[0]/e.desired_fps
time = np.linspace(0., max_time, z_s['line_geometry'].shape[-1])
print(z_s['line_geometry'].shape[0], max_time)
#smooth = 1.-np.exp(-(np.mod(time+max_time/2, max_time)-max_time/2)**2/damp_tau**2)
smooth = 1.-np.exp((np.cos(2*np.pi* time / max_time)-1)/(damp_tau / max_time)**2)
print (smooth)
fig, ax = plt.subplots(figsize=(15, 3))
_ = ax.plot(time, smooth)
In [12]:
angle_actuel = np.linspace(-1.5*np.pi, 1.5*np.pi, 300)
angle_actuel_ = np.mod(angle_actuel + np.pi/2, np.pi) - np.pi/2
fig, ax = plt.subplots(figsize=(15, 3))
_ = ax.plot(angle_actuel, angle_actuel_)
In [17]:
! git add ../mat/master_dimanche.npy ../scenario_line_master_dimanche.py
!git d *py
!git s
In [14]:
!git commit -am' scenario master HACK3R du dimanche '
In [15]:
! git push
In [16]:
%pwd
Out[16]: